import request from '@/plugin/axios'

export function list(targetUrl, data) {
    return request({
        url: targetUrl,
        method: 'get',
        params: data
    })
}

export function save(targetUrl, data) {
    if (!data.id) {
        return request({
            url: targetUrl,
            method: 'post',
            data,
        });
    } else {
        let url = targetUrl + "/" + data.id;
        return request({
            url: url,
            method: 'put',
            data
        });
    }
}
export function get(targetUrl, id) {
    let url = targetUrl + "/" + id;
    return request({
        url: url,
        method: 'get',
        loading: {
            type: 'nprogress',
            interval: 500
        }
    })
}
export function del(targetUrl, id) {
    let url = targetUrl + "/" + id;
    return request({
        url: url,
        method: 'delete'
    });
}
export function batchDelete(targetUrl, ids) {
    let url = targetUrl + "/batchdelete";
    return request({
        url: url,
        method: 'delete',
        params: {
            'datas': ids.join()
        }
    });
}
